class EventBus {
    constructor() {
        this.callbackList = {};
    }

    $on(type, callback) {
        if (this.callbackList[type]) {
            this.callbackList[type].push(callback);
        } else {
            this.callbackList[type] = [callback];
        }
    }

    $emit(type, data) {
        if (this.callbackList[type] && this.callbackList[type].length > 0) {
            this.callbackList[type].forEach((callback) => {
                callback(data);
            })
        }
    }

    $off(eventName) {
        if (eventName) {
            return delete this.callbackList[eventName];
        }
        this.callbackList = {};
    }
}

const bus = new EventBus();
bus.$on('login', (name) => {
    console.log(name);
});

setTimeout(() => {
    bus.$emit('login', '李四');
}, 1000);